package com.qf.openapi.web.master.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Api {
    private Integer id; //主键
    private String gatewayApiName; //路由器名称
    private String insideApiUrl; //服务接口地址
    private String serviceId; //服务名称
    private String description; //介绍信息
    private Integer state; //状态1有效，0无效
    private Integer idempotents; //幂等性1幂等，0非幂等
    private Integer needfee; //是否收费1收费0免费
    
    public Api(String gatewayApiName, String insideApiUrl, String serviceId, String description, Integer state, Integer idempotents, Integer needfee) {
        this.gatewayApiName = gatewayApiName;
        this.insideApiUrl = insideApiUrl;
        this.serviceId = serviceId;
        this.description = description;
        this.state = state;
        this.idempotents = idempotents;
        this.needfee = needfee;
    }
    
    public static Api cvsToApi(String s) {
        
        final String[] split = s.split(",");
        String gatewayApiName = split[0];
        String insideApiUrl = split[1];
        String serviceId = split[2];
        String description = split[3];
        Integer state = Integer.valueOf(split[4]);
        Integer idempotents = Integer.valueOf(split[5]);
        Integer needfee = Integer.valueOf(split[6]);
        
        return new Api(gatewayApiName, insideApiUrl, serviceId, description, state, idempotents, needfee);
    }
}